#include <iostream>
#include <vector>

using namespace std;
/**
 * @brief
 * 1 <= words.length <= 10^4
 * 1 <= allowed.length <= 26
 * 1 <= words[i].length <= 10
 * The characters in allowed are distinct.
 * words[i] and allowed contain only lowercase English letters.
 *
 */
class Solution
{
public:
    int countConsistentStrings(string allowed, vector<string> words)
    {
        int count = 0;
        for (int i = 0; i < words.size(); i++)
        {
            bool isAllowed = true;
            for (char c : words[i])
            {
                if (allowed.find_first_of(c) == -1)
                {
                    isAllowed = false;
                    break;
                }
            }
            if (isAllowed)
            {
                count++;
            }
        }
        return count;
    }

    int countConsistentStrings_1(string allowed, vector<string> &words)
    {
        bool found[26];
        for (int i = 0; i < 26; ++i)
        {
            found[i] = false;
            // cout << found[i] << endl;
        }
        for (const char &ch : allowed)
        {
            found[ch - 'a'] = true;
        }

        int cnt = 0;

        for (const string &str : words)
        {
            ++cnt;
            for (const char &ch : str)
            {
                if (!found[ch - 'a'])
                {
                    --cnt;
                    break;
                }
            }
        }

        return cnt;
    }

    int countConsistentStrings_2(string allowed, vector<string> &words)
    {
        int arr[26] = {0};
        for (const auto &c : allowed)
        {
            arr[c - 'a'] = 1;
        }

        int count = 0;
        for (const auto &string : words)
        {
            bool check = true;
            for (const auto &ch : string)
            {
                if (arr[ch - 'a'] == 0)
                {
                    check = false;
                    break;
                }
            }
            if (check)
                count++;
        }
        return count;
    }
};
int main()
{
    Solution s;
    string allowed = "ab";
    cout << s.countConsistentStrings(allowed, {"ad", "bd", "aaab", "baa", "badab"}) << endl;
    return 0;
}
